package com.rattsoftware.client.widgets;

import java.util.Arrays;

import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.rattsoftware.client.model.SettingsModel;

public class CoursePanel extends ContentPanel {
	
	private Grid<SettingsModel> grid;
	private ListStore<SettingsModel> store;

	public CoursePanel() {
		setLayout(new FitLayout());

		ToolBar toolBar = new ToolBar();
		Button create = new Button("New");
		create.setIcon(IconHelper.createStyle("icon-email-add"));
		toolBar.add(create);

		Button reply = new Button("Edit");
		reply.setIcon(IconHelper.createStyle("icon-email-reply"));
		toolBar.add(reply);

		setHeading("Course Management");
		setTopComponent(toolBar);

		ColumnConfig courseId = new ColumnConfig("courseid",
				"Course Id", 200);
		ColumnConfig courseName = new ColumnConfig("name", "Course Name",
				100);
		ColumnConfig duration = new ColumnConfig("duration",
				"Course Duration", 100);
		
		ColumnConfig noOfCourseUnits = new ColumnConfig("noofcourseunits",
				"No Of Course Units", 200);
		ColumnConfig noOfSemester = new ColumnConfig("noofsemester", "No Of Semesters",
				100);
		ColumnConfig courseDescription = new ColumnConfig("coursedescription",
				"Course Description", 100);

		ColumnModel cm = new ColumnModel(Arrays.asList(courseId, courseName,
				duration, noOfCourseUnits, noOfSemester, courseDescription));

		store = new ListStore<SettingsModel>();

		grid = new Grid<SettingsModel>(store, cm);
		grid.getView().setForceFit(true);
		grid.getSelectionModel().addSelectionChangedListener(
				new SelectionChangedListener<SettingsModel>() {
					@Override
					public void selectionChanged(
							SelectionChangedEvent<SettingsModel> se) {
						// MailItem m = se.getSelectedItem();
						// showMailItem(m);
					}
				});

		add(grid);
	}

	public ListStore<SettingsModel> getStore() {
		return store;
	}

	public Grid<SettingsModel> getGrid() {
		return grid;
	}
}
